﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace CricketHub
{
    public class Teamprofile
    {
        public TeamProfile nw;
        HttpWebRequest request;// = (HttpWebRequest)WebRequest.Create("http://www.myworkdemos.com/demo1/bp1/feeds/cricket_news.php?category=Teams");

        public void Requesting_url()
        {
            try
            {
                request = (HttpWebRequest)WebRequest.Create("http://www.myworkdemos.com/demo1/bp1/feeds/cricket_news.php?category=Teams");
                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(Resp), this);
            }
            catch (Exception ll)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the Network Connection");
                });
 
            }

        }
        private void Resp(IAsyncResult result)
        {
            try
            {
                Teamprofile req = (Teamprofile)result.AsyncState;
                HttpWebRequest request1 = request;
                HttpWebResponse response = (HttpWebResponse)request1.EndGetResponse(result);
                Stream steamdata = response.GetResponseStream();
                StreamReader reader = new StreamReader(steamdata);
                string global = reader.ReadToEnd();

                nw.UpdateList(global);
            }
            catch (Exception server)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Please Check the Network Connection");
                    });
            }

        }
    }
}
